home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ABUSESRC.ZIP / AbuseSrc / imlib / visobj.c < prev    next >
C/C++ Source or Header  |  1996-04-11  |  1KB  |  77 lines

  1. #include "visobj.hpp"
  2.  
  3. void image_visual::draw(image *screen, int x, int y, 
  4.             window_manager *wm, filter *f)
  5.   if (f)
  6.     f->put_image(screen,im,x,y,1);
  7.   else
  8.     im->put_image(screen,x,y); 
  9. }
  10.  
  11.  
  12. string_visual::string_visual(char *string, int Color)
  13. {
  14.   st=strcpy((char *)jmalloc(strlen(string)+1,"string visual"),string);
  15.   color=Color;
  16.   w=-1; 
  17. }
  18.  
  19.  
  20. int string_visual::width(window_manager *wm)
  21. {
  22.   if (w==-1)  // not calculated yet
  23.   {
  24.     int fw=wm->font()->width(),fh=wm->font()->height(),maxw=0;
  25.     char *info=st;
  26.     for (w=fw,h=fh+1;*info;info++)
  27.     {
  28.       if (w>maxw) maxw=w;
  29.       if (*info=='\n')
  30.       {
  31.     h+=fh+1;
  32.     w=1;
  33.       }
  34.       else w+=fw;      
  35.     }
  36.     w=maxw;
  37.   }
  38.   return w;
  39. }
  40.  
  41. int string_visual::height(window_manager *wm)
  42.   if (w==-1) width(wm);
  43.   return h;
  44. }
  45.  
  46.  
  47. static void put_para(image *screen, char *st, int dx, int dy, 
  48.              int xspace, int yspace, JCFont *font, int color)
  49. {
  50.   int ox=dx;
  51.   while (*st)
  52.   {
  53.     if (*st=='\n')
  54.     {
  55.       dx=ox;
  56.       dy+=yspace;
  57.     }
  58.     else
  59.     {
  60.       font->put_char(screen,dx,dy,*st,color);
  61.       dx+=xspace;
  62.     }
  63.     st++;
  64.   }
  65. }
  66.  
  67. void string_visual::draw(image *screen, int x, int y, 
  68.             window_manager *wm, filter *f)
  69.  
  70.   put_para(screen,st,x+1,y+1,wm->font()->width(),wm->font()->height(),
  71.        wm->font(),f ? f->get_mapping(color) : color);
  72. }
  73.  
  74.